import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'
import guidePage from '../components/guidePage.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:"/recommend"
  },
  {
    path:"/guidePage",
    name:"guidePage",
    component:guidePage
  },
  {
    path:"/recommend",
    name:"recommend",
    // 添加路由元信息
    meta:{
      headerNav:true
  },
    component:recommend
  },
  {
    path:"/recommendlist",
    name:"recommendlist",
    component:()=>import("../views/recommendlist.vue")
  },
  {
    path:"/rank",
    name:"rank",
    // 添加路由元信息
    meta:{
      headerNav:true
  },
    component:()=>import("../views/rank.vue")
  },
  {
    path:"/ranklist",
    name:"ranklist",
    component:()=>import("../views/ranklist.vue")
  },
  {
    path:"/singer",
    name:"singer",
    // 添加路由元信息
    meta:{
      headerNav:true
  },
    component:()=>import("../views/singer.vue")
  },
  {
    path:"/singerlist",
    name:"singerlist",
    component:()=>import("../views/singerlist.vue")
  },
  {
    path:"/mv",
    name:"mv",
    meta:{
      headerNav:true
  },
    component:()=>import("../views/mv.vue")
  },
  {
    path:"/comment",
    name:"comment",
    component:()=>import("../views/comment.vue")
  },
  {
    path:"/login",
    name:"login",
  
    component:()=>import("../views/login.vue")
  },
  {
    path:"/search",
    name:"search", 
    component:()=>import("../views/search.vue")
  },
  {
    path:"/history",
    name:"history", 
    component:()=>import("../views/history.vue")
  },
  {
    path:'/userInfo',
    name:"userInfo",
    component:()=>import("../views/userInfo.vue"),
    // 独享路由守卫
    // beforeEnter: (to, from, next) => {
    //   let login = window.localStorage.getItem("login");
    //   // 判断登录情况
    //   if(!login){
    //     next("/login");
    //     return 
    //   }else{
    //     next();
    //   }
    // }
  },
  {
    path:"/likelist",
    name:"likelist", 
    component:()=>import("../views/likelist.vue")
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  linkActiveClass :"active",
  routes
})
router.beforeEach((to,from,next)=>{
  let login = window.localStorage.getItem("login");
  // 登录界面
  if(to.path == "/login"){
    next();
    return;
  }else{
    // 判断登录情况
    if(!login){
      next("/login");
      return;
    }else{
      next();
    }
  }
})
export default router
